// 访问类型，
//private 只有当前类内部能访问
//public 类的内，子类，实例都可以访问，不写的话，默认是public
// protected 类内和子类能访问
class PersonClass {
  public name: string
  protected sex: string
  private age: number
  constructor(age: number, sex: string, name: string) {
    this.age = age
    this.sex = sex
    this.name = name
  }
  getAge() {
    return this.age
  }
}

const p1 = new PersonClass(12, "man", "dell")
console.log(p1.getAge())

//constructor 构造函数
class PersonClass2 {
  //常规在初始化时给属性赋值
  // name: string
  // constructor(name: string) {
  //   this.name = name
  // }

  //简化写发
  constructor(public name: string) {}
  private lan: string = "chinese"
  sayHi() {
    return this.name
  }
}
const p2 = new PersonClass2("lee")
console.log(p2.name)

// 类的继承
// 如果子类重写了constructor，则必须在构造中调用super() 来执行父类的构造
class TeacherClass extends PersonClass2 {
  constructor() {
    super("teacher1")
  }
  // 子类中如果像想调用父类的方法或属性用super.method()
  sayHi() {
    return super.sayHi() + "hello"
  }
}
// 子类的构造函数中必须调用super()
class XYS extends TeacherClass {
  constructor() {
    super()
  }
}
